﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace CSF.Utility.Mvc
{
    public class HtmlUtility
    {
        public static string Encode(string text)
        {
            string result = HttpUtility.HtmlEncode(text);
            if (result != null)
                result = Regex.Replace(result, "\r\n|\r|\n", "<br/>");
            return result;
        }

        public static string Decode(string text)
        {
            string result = HttpUtility.HtmlDecode(text);
            if (result != null)
                result = Regex.Replace(result, @"<br\s*/?>", "\r\n");
            return result;
        }
    }
}